package com.css.dzj.zfjg.modules.detail.service.impl;


import com.css.dzj.zfjg.common.util.R;
import com.css.dzj.zfjg.common.util.ServiceUtil;
import com.css.dzj.zfjg.common.util.excel.ExcelData;
import com.css.dzj.zfjg.common.util.excel.ExcelUtil;
import com.css.dzj.zfjg.common.util.excel.ExportExcelUtils;
import com.css.dzj.zfjg.modules.clue.entity.Clue;
import com.css.dzj.zfjg.modules.clue.service.ClueService;
import com.css.dzj.zfjg.modules.detail.entity.CreditPushInfo;
import com.css.dzj.zfjg.modules.detail.entity.Detail;
import com.css.dzj.zfjg.modules.detail.entity.QDetail;
import com.css.dzj.zfjg.modules.detail.mapper.CreditPushInfoMapper;
import com.css.dzj.zfjg.modules.detail.mapper.DetailMapper;
import com.css.dzj.zfjg.modules.detail.service.DetailService;
import com.css.dzj.zfjg.modules.detail.vo.Infopush;
import com.css.dzj.zfjg.common.util.page.PageBean;
import com.querydsl.core.QueryResults;
import com.querydsl.core.types.ExpressionUtils;
import com.querydsl.core.types.Predicate;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.apache.poi.ss.usermodel.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import javax.persistence.EntityManager;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.regex.Pattern;

@Service
public class DetailServiceImpl implements DetailService {
    @Autowired
    private DetailMapper detailMapper;
    @Autowired
    private ClueService clueService;
    @Autowired
    private CreditPushInfoMapper creditPushInfoMapper;
    @Autowired
    private JPAQueryFactory jpaQueryFactory;
    @Autowired
    private EntityManager entityManager;
    @Autowired
    private HttpServletRequest request;

    @Override
    public void add(Detail detail) {
        if (detail == null) {
            throw new RuntimeException("信用详情不能为空");
        }
        detail.setCreateUser(ServiceUtil.getLoginName(request));
        detail.setCreateTime(new Date());
        detailMapper.save(detail);
    }

    @Override
    public void update(Detail detail) {
        if (detail == null || StringUtils.isEmpty(detail.getId())) {
            throw new RuntimeException("信用详情或者ID不能为空");
        }
        // detail.setUpdateUser(ServiceUtil.getLoginName(request));
        detail.setUpdateTime(new Date());
        detailMapper.save(detail);
    }

    @Override
    public Detail findById(String id) {
        if (StringUtils.isEmpty(id)) {
            throw new RuntimeException("ID为空");
        }
        return detailMapper.getOne(id);
    }

    @Override
    public QueryResults<Detail> getPage(String enterpriseName, String enterpriseClassification, String enterpriseScoreBegin, String enterpriseScoreEnd,
                                        String status, Pageable pageable) {
        QDetail q = QDetail.detail;
        Predicate predicate = q.isNotNull().or(q.isNull());
        /**
         * 拼接查询条件
         */
        predicate = (StringUtils.isEmpty(enterpriseName)) ? predicate : ExpressionUtils.and(predicate, q.enterpriseName.like("%" + enterpriseName + "%"));
        predicate = (StringUtils.isEmpty(enterpriseClassification)) ? predicate : ExpressionUtils.and(predicate, q.enterpriseClassification.eq(enterpriseClassification));
        if (!StringUtils.isEmpty(enterpriseScoreBegin) && StringUtils.isEmpty(enterpriseScoreEnd)) {
            // 只有开始企业分数不为空 --> 查询大于该分数的
            if (!isInteger(enterpriseScoreBegin)){
                throw new RuntimeException("请输入整数！");
            }
            predicate = ExpressionUtils.and(predicate, q.enterpriseScore.gt(enterpriseScoreBegin.toString()));
        } else if (StringUtils.isEmpty(enterpriseScoreBegin) && !StringUtils.isEmpty(enterpriseScoreEnd)) {
            // 只有结束企业分数不为空 --> 查询小于该分数的
            if (!isInteger(enterpriseScoreEnd)){
                throw new RuntimeException("请输入整数！");
            }
            predicate = ExpressionUtils.and(predicate, q.enterpriseScore.lt(enterpriseScoreEnd));
        } else if (!StringUtils.isEmpty(enterpriseScoreBegin) && !StringUtils.isEmpty(enterpriseScoreEnd)) {
            // 开始和结束企业分数都不为空 --> 查询处于两者之间的
            if (!isInteger(enterpriseScoreEnd) || !isInteger(enterpriseScoreBegin)){
                throw new RuntimeException("请输入整数！");
            }
            if (enterpriseScoreBegin.compareTo(enterpriseScoreEnd)  > 0){
                throw new RuntimeException("开始分数不可以小于结束分数！");
            }
            predicate = ExpressionUtils.and(predicate, q.enterpriseScore.between(enterpriseScoreBegin,enterpriseScoreEnd));
        }
        predicate = (StringUtils.isEmpty(status)) ? predicate : ExpressionUtils.and(predicate, q.status.eq(status));
        // 返回结果
        return jpaQueryFactory.selectFrom(q).where(predicate).orderBy(q.createTime.desc())
                .offset(pageable.getOffset())
                .limit(pageable.getPageSize())
                .fetchResults();
    }

    /*
     * 判断是否为整数
     * @param str 传入的字符串
     * @return 是整数返回true,否则返回false
     */

    public static boolean isInteger(String str) {
        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
        return pattern.matcher(str).matches();
    }

    public static void main(String[] args) {
        System.out.println(isInteger("1234"));
        System.out.println(isInteger("1234a"));
        System.out.println(isInteger(" 1234"));
        System.out.println("---------------------");
        System.out.println("1".compareTo("0"));
        System.out.println("2000".compareTo("3000"));
        System.out.println("000".compareTo("000"));
    }

    @Transactional
    @Override
    public void addDetailFromExcel(MultipartFile file) throws Exception {
        // 获取原始文件名
        String originalFilename = file.getOriginalFilename();
        // 获取文件类型
        String fileType = originalFilename.substring(originalFilename.lastIndexOf(".") + 1);
        // 从第一行开始读取
        Integer startRows = 1;
        // 获取输入流
        InputStream is = file.getInputStream();
        // Excel导入导出的单元类
        List<String[]> strings = ExcelUtil.readData(fileType, startRows, true, is);
        // Excel行数据重复
        String message = this.lineRepeat(strings);
        if (message != null) {
            throw new RuntimeException("企业证件号码:" + message + "行重复!");
        }
        for (String[] list : strings) {
            // 企业证件号码重复时，覆盖原有数据
            if (isRepeatByEnterpriseIdNumber(list[1])) {
                Detail detail = queryByenterpriseIdNumber(list[1]);
                updDetail(detail, list);
                continue;
            }
            // 将字符串数组数据转换为Detail实体,并且向数据库添加实体数据
            Detail detail = castDetail(list);
            // 评估状态为已接收
            detail.setStatus("0");
            add(detail);
        }
    }

    private String lineRepeat(List<String[]> strings) {
        HashSet<String> set = new HashSet<>();
        for (String[] s : strings) {
            // s[1]为：企业证件号码
            String message = s[1];
            if (set.contains(message)) {
                return message;
            }
            set.add(message);
        }
        return null;
    }

    /**
     * 根据企业证件号码查询
     *
     * @param enterpriseIdNumber
     * @return
     */
    private Detail queryByenterpriseIdNumber(String enterpriseIdNumber) {
        QDetail q = QDetail.detail;
        return jpaQueryFactory.selectFrom(q).where(q.enterpriseIdNumber.eq(enterpriseIdNumber)).fetchFirst();
    }

    /**
     * 更新覆盖原有数据
     *
     * @param detail
     * @param s
     */
    private void updDetail(Detail detail, String[] s) {
        try {
            detail.setEnterpriseName(s[0]);// 企业名称
            detail.setEnterpriseIdType(s[2]);// 企业证件类型
            detail.setEnterpriseScore(s[3]);// 企业分数
            detail.setEnterpriseClassification(s[4]);// 企业分类
            detail.setAssessmentDate(DateUtil.parseYYYYMMDDDate(s[5]));// 评估日期
            detail.setFeedbackPerson(s[6]);// 反馈人
            detail.setFeedbackOrg(s[7]);// 反馈人机构
            detail.setFeedbackTime(DateUtil.parseYYYYMMDDDate(s[8]));// 反馈时间
            detail.setStatus("0");// 信用评估状态为已接收
        } catch (IllegalArgumentException e) {
            throw new RuntimeException("日期格式应符合YYYY/MM/DD或者YYYY-MM-DD格式！");
        } catch (ArrayIndexOutOfBoundsException e) {
            throw new RuntimeException("表中缺少一列或多列！");
        }
        update(detail);
    }

    @Override
    public void exportDetailToExcel(HttpServletResponse response, List<Detail> details) {
        if (details == null || details.size() < 0) {
            throw new RuntimeException("信用集合为空");
        }
        // 创建导出实体
        ExcelData data = new ExcelData();
        data.setName("企业信用信息表");
        /**
         * 设置Excel标题
         */
        ArrayList<String> titles = new ArrayList<>();
        titles.add("企业名称");
        titles.add("企业证件号码");
        titles.add("企业证件类型");
        titles.add("企业分数");
        titles.add("企业分类");
        titles.add("评估日期");
        titles.add("信用评估状态");
        titles.add("反馈人");
        titles.add("反馈人机构");
        titles.add("反馈时间");
        data.setTitles(titles);
        /**
         * 处理行数据
         */
        ArrayList<List<Object>> rows = new ArrayList<>();
        for (Detail detail : details) {
            ArrayList<Object> row = new ArrayList<>();
            row.add(detail.getEnterpriseName());
            row.add(detail.getEnterpriseIdNumber());
            row.add(detail.getEnterpriseIdType());
            row.add(detail.getEnterpriseScore());
            row.add(detail.getEnterpriseClassification());
            row.add(detail.getAssessmentDate());
            row.add(detail.getStatus());
            row.add(detail.getFeedbackPerson());
            row.add(detail.getFeedbackOrg());
            row.add(detail.getFeedbackTime());
            rows.add(row);
        }
        data.setRows(rows);
        try {
            // 导出
            ExportExcelUtils.exportExcel(response, "企业信用信息表.xlsx", data);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public Detail castDetail(String[] s) {
        Detail detail = new Detail();
        /**
         * 设置excel表格对应的必填字段
         */
        try {
            detail.setEnterpriseName(s[0]);// 企业名称
            detail.setEnterpriseIdNumber(s[1]);// 企业证件号码
            detail.setEnterpriseIdType(s[2]);// 企业证件类型
            detail.setEnterpriseScore(s[3]);// 企业分数
            detail.setEnterpriseClassification(s[4]);// 企业分类
            detail.setAssessmentDate(DateUtil.parseYYYYMMDDDate(s[5]));// 评估日期
//            detail.setStatus(chinseseToNumber(s[6]));// 信用评估状态
            detail.setFeedbackPerson(s[6]);// 反馈人
            detail.setFeedbackOrg(s[7]);// 反馈人机构
            detail.setFeedbackTime(DateUtil.parseYYYYMMDDDate(s[8]));// 反馈时间
        } catch (IllegalArgumentException e) {
            throw new RuntimeException("日期格式应符合YYYY/MM/DD或者YYYY-MM-DD格式！");
        } catch (ArrayIndexOutOfBoundsException e) {
            throw new RuntimeException("表中缺少一列或多列！");
        }
        return detail;
    }


    @Override
    public Boolean isRepeatByEnterpriseIdNumber(String enterpriseIdNumber) {
        QDetail q = QDetail.detail;
        return jpaQueryFactory.selectFrom(q)
                .where(q.enterpriseIdNumber.eq(enterpriseIdNumber))
                .fetchCount() > 0;
    }

    /**
     * 通过企业证件号码查询企业信用详情
     *
     * @param enterpriseIdNumber
     * @return
     */
    @Override
    public Detail queryByIdNumber(String enterpriseIdNumber) {
        QDetail qDetail = QDetail.detail;
        return jpaQueryFactory.selectFrom(qDetail)
                .where(qDetail.enterpriseIdNumber.eq(enterpriseIdNumber))
                .fetchOne();
    }

    @Override
    public List<Detail> queryByIds(String ids) {
        if (StringUtils.isEmpty(ids)) {
            throw new RuntimeException("ids为空!");
        }
        List<String> idList = Arrays.asList(ids.split(","));
        List<Detail> details = detailMapper.findAllById(idList);
        // 对status状态进行转换
        for (Detail detail : details) {
            String status = detail.getStatus();
            detail.setStatus(numberToChinsese(status));
        }
        return details;
    }

    /**
     * @param pageable
     * @return
     */
    @Override
    public PageBean<Infopush> groupBy(Pageable pageable) {
        PageBean<Infopush> page = new PageBean<>();

        String month = getYearAndMonth();
        ArrayList<Infopush> infopushes = new ArrayList<>();
        List<Object[]> infos = creditPushInfoMapper.list(pageable);
        for (Object[] info : infos) {
            String monthNumber = creditPushInfoMapper.getMonthNumber(month, info[0].toString());
            Infopush infopush = new Infopush();
            infopush.setProvice(info[0].toString());
            infopush.setTotalNumber(info[1].toString());
            infopush.setCurrentMonthNumber(monthNumber);
            infopushes.add(infopush);
        }
        // 设置分页信息
        page.setList(infopushes);
        page.setCurrentCount(pageable.getPageSize());
        page.setCurrentPage(pageable.getPageNumber());
        // 获取总数量
        /*QDetail qDetail = QDetail.detail;
        int count = (int) jpaQueryFactory.selectFrom(qDetail).groupBy(qDetail.feedbackOrg).fetchCount();*/
        int count = infos.size();
        page.setTotalRecord(count);
        int totalPage = (count + pageable.getPageSize() - 1) / pageable.getPageSize();
        page.setTotalPage(totalPage);
        return page;
    }

    @Override
    public List<Detail> queryByParams(String enterpriseName, String enterpriseClassification, String enterpriseScoreBegin, String enterpriseScoreEnd, String status) {
        QDetail q = QDetail.detail;
        Predicate predicate = q.isNotNull().or(q.isNull());
        /**
         * 拼接查询条件
         */
        predicate = (StringUtils.isEmpty(enterpriseName)) ? predicate : ExpressionUtils.and(predicate, q.enterpriseName.like("%" + enterpriseName + "%"));
        predicate = (StringUtils.isEmpty(enterpriseClassification)) ? predicate : ExpressionUtils.and(predicate, q.enterpriseClassification.eq(enterpriseClassification));
        if (!StringUtils.isEmpty(enterpriseScoreBegin) && StringUtils.isEmpty(enterpriseScoreEnd)) {
            // 只有开始企业分数不为空 --> 查询大于该分数的
            if (!isInteger(enterpriseScoreBegin)){
                throw new RuntimeException("请输入整数！");
            }
            predicate = ExpressionUtils.and(predicate, q.enterpriseScore.gt(enterpriseScoreBegin));
        } else if (StringUtils.isEmpty(enterpriseScoreBegin) && !StringUtils.isEmpty(enterpriseScoreEnd)) {
            // 只有结束企业分数不为空 --> 查询小于该分数的
            if (!isInteger(enterpriseScoreEnd)){
                throw new RuntimeException("请输入整数！");
            }
            predicate = ExpressionUtils.and(predicate, q.enterpriseScore.lt(enterpriseScoreBegin));
        } else if (!StringUtils.isEmpty(enterpriseScoreBegin) && !StringUtils.isEmpty(enterpriseScoreEnd)) {
            // 开始和结束企业分数都不为空 --> 查询处于两者之间的
            if (!isInteger(enterpriseScoreEnd) || !isInteger(enterpriseScoreBegin)){
                throw new RuntimeException("请输入整数！");
            }
            if (enterpriseScoreBegin.compareTo(enterpriseScoreEnd)  > 0){
                throw new RuntimeException("开始分数不可以小于结束分数！");
            }
            predicate = ExpressionUtils.and(predicate, q.enterpriseScore.between(enterpriseScoreBegin, enterpriseScoreEnd));
        }
        predicate = (StringUtils.isEmpty(status)) ? predicate : ExpressionUtils.and(predicate, q.status.eq(status));
        // 返回结果
        List<Detail> details = jpaQueryFactory.selectFrom(q).where(predicate).orderBy(q.createTime.desc()).fetch();
        // 对status状态进行转换
        for (Detail detail : details) {
            String detailStatus = detail.getStatus();
            detail.setStatus(numberToChinsese(detailStatus));
        }
        return details;
    }

    /**
     * 企业信用，信用线索反馈
     *
     * @param detail
     * @param clue
     */
    @Override
    @Transactional
    public void feedback(Detail detail, Clue clue, CreditPushInfo creditPushInfo) {
        this.update(detail);
        if (clue != null) {
            clueService.update(clue);
        }
        creditPushInfoMapper.save(creditPushInfo);
    }

    /**
     * 获取年月
     *
     * @return
     */
    public String getYearAndMonth() {
        Date d = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        String dateNowStr = sdf.format(d);
        return dateNowStr;
    }

    /**
     * 获取当前日期的月初Date
     *
     * @return
     */
    public Date getFirstDay() {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime localDateTime = date.with(TemporalAdjusters.firstDayOfMonth());
        ZoneId zoneId = ZoneId.systemDefault();
        ZonedDateTime zdt = localDateTime.atZone(zoneId);//Combines this date-time with a time-zone to create a  ZonedDateTime.
        return Date.from(zdt.toInstant());
    }

    /**
     * 获取当前日期的月初Date
     *
     * @return
     */
    public Date getLastDay() {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime localDateTime = date.with(TemporalAdjusters.lastDayOfMonth());
        ZoneId zoneId = ZoneId.systemDefault();
        ZonedDateTime zdt = localDateTime.atZone(zoneId);//Combines this date-time with a time-zone to create a  ZonedDateTime.
        return Date.from(zdt.toInstant());
    }

    /**
     * 数字标识转换为汉字
     *
     * @param num
     * @return
     */
    private String chinseseToNumber(String num) {
        // 信用评估状态 0:已接收 1:已调整 2：已反馈
        if ("已接收".equals(num)) {
            num = "0";
        } else if ("已调整".equals(num)) {
            num = "1";
        } else if ("已反馈".equals(num)) {
            num = "2";
        }
        return num;
    }

    /**
     * 汉字标识转换为数字
     *
     * @param num
     * @return
     */
    private String numberToChinsese(String num) {
        // 信用评估状态 0:已接收 1:已调整 2：已反馈
        if ("0".equals(num)) {
            num = "已接收";
        } else if ("1".equals(num)) {
            num = "已调整";
        } else if ("2".equals(num)) {
            num = "已反馈";
        }
        return num;
    }
    /**
     * 根据参数导出数据到Excel
     * @param enterpriseName
     * @param  enterpriseScoreBegin
     * @param  enterpriseScoreEnd
     * @param  enterpriseClassification
     */
    @Override
    public List<Detail> queryByParams(String enterpriseName, String enterpriseScoreBegin,String enterpriseScoreEnd , String enterpriseClassification) {
        List<Detail> jgLhjgCreditAssessEntities = new ArrayList<Detail>();
        QDetail qZfjgJgLhjgCreditAssessEntity = QDetail.detail;
        Predicate predicate = qZfjgJgLhjgCreditAssessEntity.isNotNull().or(qZfjgJgLhjgCreditAssessEntity.isNull());
        predicate = (enterpriseName == null || enterpriseName.isEmpty()) ? predicate : ExpressionUtils.and(predicate, qZfjgJgLhjgCreditAssessEntity.enterpriseName.like("%" + enterpriseName + "%"));
        predicate = (enterpriseClassification == null || enterpriseClassification.isEmpty()) ? predicate : ExpressionUtils.and(predicate, qZfjgJgLhjgCreditAssessEntity.enterpriseClassification.eq(enterpriseClassification));
        if ((StringUtils.isEmpty(enterpriseScoreBegin)) && (!org.springframework.util.StringUtils.isEmpty(enterpriseScoreEnd))) {
            try{
                predicate = ExpressionUtils.and(predicate, qZfjgJgLhjgCreditAssessEntity.enterpriseScore.goe(enterpriseScoreEnd));
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        if ((!StringUtils.isEmpty(enterpriseScoreBegin)) && (StringUtils.isEmpty(enterpriseScoreEnd))) {
            try{
                predicate = ExpressionUtils.and(predicate, qZfjgJgLhjgCreditAssessEntity.enterpriseScore.loe(enterpriseScoreBegin));
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        if ((!StringUtils.isEmpty(enterpriseScoreBegin)) && (!StringUtils.isEmpty(enterpriseScoreEnd))) {
            try{
                predicate = ExpressionUtils.and(predicate, qZfjgJgLhjgCreditAssessEntity.enterpriseScore.between(enterpriseScoreBegin, enterpriseScoreEnd));
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        jgLhjgCreditAssessEntities = jpaQueryFactory.selectFrom(qZfjgJgLhjgCreditAssessEntity)
                .where(predicate)
                .orderBy(qZfjgJgLhjgCreditAssessEntity.createTime.desc())
                .fetch();
        return jgLhjgCreditAssessEntities;
    }

    @Override
    public R checkName(MultipartFile file) throws Exception {
        // 获取原始文件名
        String originalFilename = file.getOriginalFilename();
        // 获取文件类型
        String fileType = originalFilename.substring(originalFilename.lastIndexOf(".") + 1);
        // 从第一行开始读取
        Integer startRows = 1;
        // 获取输入流
        InputStream is = file.getInputStream();
        // Excel导入导出的单元类
        List<String[]> strings = ExcelUtil.readData(fileType, startRows, true, is);
        // Excel行数据重复
        String message = this.lineRepeat(strings);
        if (message != null) {
            throw new RuntimeException("企业证件号码:" + message + "行重复!");
        }
        boolean isExist = false;
        String existMessage = "";
        HashSet<String> numSet = new HashSet<>();
        for (String[] list : strings) {
            // 企业证件号码重复时，覆盖原有数据
            if (isRepeatByEnterpriseIdNumber(list[1])) {
                Detail detail = queryByenterpriseIdNumber(list[1]);
                if(detail != null) {
                    if(StringUtils.isEmpty(list[0])) {
                        throw new RuntimeException("企业名称不能为空");
                    }
                    if(!list[0].equals(detail.getEnterpriseName())) {
                        isExist = true;
                        numSet.add(list[1]);
                    }
                }
            }
            if(clueService.isRepeatByEnterpriseIdNumber(list[1])) {
                Clue clue = clueService.queryByenterpriseIdNumber(list[1]);
                if(clue != null) {
                    if(StringUtils.isEmpty(list[0])) {
                        throw new RuntimeException("企业名称不能为空！");
                    }
                    if(!list[0].equals(clue.getEnterpriseName())) {
                        isExist = true;
                        numSet.add(list[1]);
                    }
                }
            }
        }
        existMessage = numSet.toString();
        return R.ok().put("isExist", isExist).put("existMessage", existMessage);
    }

    // 企业信用信息批量反馈 ---- 需要对接应急部，应急部接口未实现
    @Override
    public void importToRemote(MultipartFile file, HttpServletRequest request) throws Exception {
        // 获取原始文件名
        String originalFilename = file.getOriginalFilename();
        // 获取文件类型
        String fileType = originalFilename.substring(originalFilename.lastIndexOf(".") + 1);
        // 从第一行开始读取
        Integer startRows = 1;
        // 获取输入流
        InputStream is = file.getInputStream();
        // Excel导入导出的单元类
        List<String[]> strings = ExcelUtil.readData(fileType, startRows, true, is);
        // Excel行数据重复
        String message = this.lineRepeat(strings);
        if (message != null) {
            throw new RuntimeException("企业证件号码:" + message + "行重复!");
        }

        for (String[] list : strings) {
            // 将字符串数组数据转换为Detail实体
//            Detail detail = castDetail(list);
//            detailList.add(detail);

            // 添加推送信息
            CreditPushInfo creditPushInfo = new CreditPushInfo();
            creditPushInfo.setEnterpriseIdNumber(list[1]);
            creditPushInfo.setFeedbackTime(new Date());
            creditPushInfo.setFeedbackPerson(ServiceUtil.getLoginName(request));
            creditPushInfo.setFeedbackOrg(ServiceUtil.getOrgName(request));
            creditPushInfoMapper.save(creditPushInfo);
        }
    }

    @Override
    public QueryResults<Detail> getCreditInfos(Pageable pageable) {
        QDetail q = QDetail.detail;
        return jpaQueryFactory.selectFrom(q)
                .limit(pageable.getPageSize())
                .offset(pageable.getOffset())
                .orderBy(q.createTime.desc())
                .fetchResults();

    }
}
